// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: Ring Object
// Script Author: Christian Whitehead/Simon Thomley/Tails LP
// Edits by Team ReDream
// ----------------------------------

// Aliases
private alias 10 : TYPE_RING

private alias object.value1 : ring.targetPlayer

private alias 0 : STATE_UNATTRACTED
private alias 1 : STATE_ATTRACTED

// Player aliases
private alias object.state   : player.state
private alias object.xpos    : player.xpos
private alias object.ypos    : player.ypos
private alias object.value0  : player.rings
private alias object.value16 : player.isPlayer2
private alias object.value18 : player.currentPlane
private alias object.value37 : player.shield

private alias 4 : SHIELD_LIGHTNING

// Function declarations
reserve function HintRing_DebugDraw
reserve function HintRing_DebugSpawn

function HintRing_DebugDraw
	DrawSprite(0)
end function


function HintRing_DebugSpawn
	CreateTempObject(TypeName[Hint Ring], 0, object.xpos, object.ypos)
	object[tempObjectPos].drawOrder = 4
end function


event ObjectMain
	if options.gamemode == 1
		object.type = 0
	end if
	object.rotation += 4
	// Check interaction with players
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)

		// Make sure that the player isn't supposed to ignore rings right now
		CheckEqual(player[0].state, PlayerObject_Knockback)
		temp0 = checkResult
		CheckEqual(player[currentPlayer].state, PlayerObject_Knockback)
		temp0 = checkResult
		CheckEqual(player[currentPlayer].state, PlayerObject_Hurt)
		temp0 |= checkResult

		if temp0 == false
			// All checks passed, see if the player is touching the ring

			BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == true
				// Player is touching ring - collect it
				
				object.type = TypeName[Hint Ring Sparkle]
				object.value2 = 5
				object.value3 = 0
				object.propertyValue = object.propertyValue

				// Play the ring sound

				PlaySfx(SfxName[Hint], 0)
				checkResult = false
			end if
		end if
	next
end event


event ObjectDraw

	// All rings use the same frame
	// (Animation is handled by Stage Setup object)
	DrawSpriteFX(0, FX_ROTATE, object.xpos, object.ypos)
	DrawSprite(1)

end event


event ObjectStartup

	LoadSpriteSheet("Global/Items.gif")

	// Set each ring's draw order to 4
	foreach (TypeName[Hint Ring], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
	next

	// Ring frames
	SpriteFrame(-17, -17, 34, 34, 256, 34)
	SpriteFrame(-17, -17, 34, 34, 291, 34)

	SpriteFrame(-17, -17, 334, 12, 1, 379)

	// Add the Ring to the debug mode object list
	SetTableValue(TypeName[Hint Ring], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(HintRing_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(HintRing_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
	
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
